package com.lrd.shardingjdbc.service;

import com.lrd.shardingjdbc.entity.User;
import com.lrd.shardingjdbc.mapper.UserMapper;
import io.shardingsphere.transaction.annotation.ShardingTransactionType;
import io.shardingsphere.transaction.api.TransactionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author LRD
 * @create 2021-03-29 22:10
 */
@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

    //分布式事务注解
    @ShardingTransactionType(value = TransactionType.XA)
    @Transactional(rollbackFor = Exception.class)
    public int saveUser(User user){
        userMapper.addUser(user);
        return 1;
    }
}
